<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    
    function Cat(name,color){
        this.name = name;
        this.color = color;

        Object.defineProperty(this,"age",{
            value:1,
            writable:false,
            enumerable:false,
            configurable:false,
        })
    }

    Cat.prototype.species = "Cat";
    Cat.prototype.skill = function(){
        console.log("捉老鼠");
    }
    Cat.prototype.call = function(){
        console.log("喵喵");
    }
    Cat.prototype.say = function(){
        console.log(this.name,this.color);
    }

    Object.prototype.a = 1;
    Object.prototype.b = 2;
    
    var Tom = new Cat("Tom","black");
    // console.log(Tom);

    var num = new Number(100);
    var str = "hello";
    var bool = true;
    var arr = [1,2,3];
    var obj = {a:1,b:2};


    // typeof  判断数据类型的方法 (对象类型=>'object'  函数 => 'function')
    // console.log(typeof num);
    // console.log(typeof str);
    // console.log(typeof bool);
    // console.log(typeof arr);
    // console.log(typeof obj);
    // console.log(typeof Tom);

    // 判断是否是数组
    // Array.isArray()
    // instanceof  //不准确
    // console.log([] instanceof Array);
    // console.log([] instanceof Object);

    

    // var fn = function(){}
    // var div = document.createElement("div")
    // console.log(fn instanceof Object);
    // console.log(div instanceof Object);

    
    
    // 判断数据类型 (格式不统一)

    // console.dir(num);

    // console.log(num.toString());  // '100'     // num -> Number.prototype.toString -> Object.prototype.toString
    // console.log(str.toString());  // 'hello'
    // console.log(bool.toString()); // 'true'
    // console.log(arr.toString());  // '1,2,3'   // arr -> Array.prototype.toString -> Object.prototype.toString
    // console.log(obj.toString());  // '[object Object]'  Object.prototype.toString
    // console.log(Tom.toString());  // '[object Object]'

    // 所有数据统一访问Object.prototype.toString 输出结果即可保持一致

    console.log(Object.prototype.toString.call(num));
    console.log(Object.prototype.toString.call(str));
    console.log(Object.prototype.toString.call(bool));
    console.log(Object.prototype.toString.call(arr));
    console.log(Object.prototype.toString.call(obj));
    console.log(Object.prototype.toString.call(Tom));
    console.log(Object.prototype.toString.call(new Set()));
    console.log(Object.prototype.toString.call(new Map()));
    console.log(Object.prototype.toString.call(new Date()));

     // 判断一个数据是否是纯对象  {a:1, b:2}  (Object  自定义构造函数)
    console.log(Object.prototype.toString.call(Tom) === '[object Object]');
    console.log(Object.prototype.toString.call(arr) === '[object Array]');

  






</script>
</html>